package com.zret.oasys.operation.dept;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.google.gson.Gson;
import com.zret.oasys.entity.Dept;

public class UpdateDept implements DeptServletOperation {

	@Override
	public void doOperation(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException 
	{
		//编码
		response.setContentType("application/json;charset=utf-8");
		
		int deptid = Integer.valueOf(request.getParameter("deptid"));
		int managerid = Integer.valueOf(request.getParameter("managerid"));
		String deptname =request.getParameter("deptname");
		
		Dept dept  = new Dept(deptid, managerid, deptname);
		
		System.out.println(dept);
		
		boolean flag = deptservice.updateDept(dept);
		
		System.out.println(flag);
		
		//网页ajax输出
		PrintWriter out = response.getWriter();
		
		Gson gson = new Gson();
		String msg1 = gson.toJson("修改部门成功");
		String msg2 = gson.toJson("修改部门失败");
		if (flag) {
			out.print(msg1);
		}else {
			out.print(msg2);
		}
		out.close();
	}

}
